package com.tengju.user.domain.model.protocol;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AppVersionInfo {

    private String updateDesc;

    private String version;

    private Boolean needForceUpdate;

    private String apkUrl;

    public Integer compareVersion(String version) {
        int currentVersion = convertVersion(this.version);
        int compareVersion = convertVersion(version);
        if (currentVersion > compareVersion) {
            return 1;
        } else if (currentVersion == compareVersion) {
            return 0;
        } else {
            return -1;
        }
    }

    private int convertVersion(String appVersion) {
        String[] version = appVersion.split("\\.");
        return Integer.parseInt(version[0]) * 100 + Integer.parseInt(version[1]) * 10 + Integer.parseInt(version[2]);
    }


}
